package org.example;

class TaskRunner extends Thread {
    private TaskCallback callback;

    public TaskRunner(TaskCallback callback) {
        this.callback = callback;
    }

    @Override
    public void run() {
        System.out.println("task线程开始执行任务-----"+Thread.currentThread().getName());
        try {
            Thread.sleep(2000);  // 模拟耗时任务
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        String result = "任务完成,结果=42";
        // 任务完成,触发回调
        if (callback != null) {
            callback.onComplete(result);
        }
    }
}